package ren.edu.apollo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ren.edu.apollo.config.RedisConfig;
import ren.edu.apollo.config.UserConfig;

/**
 * @PackageName: ren.edu.apollo.controller
 * @ClassName: ApolloController
 * @Description:
 * @author: RZS
 * @date: 2021/7/17  21:27
 */
@RestController
@RequestMapping("/apollo")
public class ApolloController {

    /**************************Placeholder 注入配置*******************************/
    /**
     * Placeholder 注入配置
     * 用户名, 默认值为zhangsan
     */
    @Value("${username:zhangsan}")
    private String username;

    @GetMapping("/username")
    public String apolloGetUsername(){
        return username;
    }

    /**************************Java Config 使用方式*******************************/
    /**
     * Java Config 使用方式
     */
    @Autowired
    private UserConfig userConfig;

    @GetMapping("/user-config")
    public String apolloUserConfig(){
        return userConfig.getUsername();
    }

    /**************************ConfigurationProperties 使用方式*******************************/
    /**
     * ConfigurationProperties 使用方式
     */
    @Autowired
    private RedisConfig redisConfig;

    @GetMapping("/redis-config")
    public String apolloRedisConfig(){
        return redisConfig.getHost();
    }
}
